import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

public class Http {
    public static void main(String[] args) {
        OkHttpClient client = new OkHttpClient();
        ObjectMapper om = new ObjectMapper();

        int page = 1;
        while (true) {
            String url = "https://prts.maa.plus/copilot/query?desc=true&limit=50&page=" + page + "&order_by=views";
            Request request = new Request.Builder()
                    .url(url)
                    .build();
            try (Response response = client.newCall(request).execute()) {
                System.out.println(page);
                if (response.body() == null) {
                    break;
                }
                String body = response.body().string();
                JsonNode node = om.readTree(body);
                if (!node.get("data").get("has_next").asBoolean()) {
                    break;
                }
            } catch (IOException e) {
                throw new RuntimeException(e.getMessage());
            }
            page++;
        }
    }
}
